package com.hxl.tech.gateway.auth.dao;


import com.hxl.tech.gateway.auth.model.OpenApiApproval;
import com.hxl.tech.gateway.auth.model.QOpenApiApproval;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;
import javax.annotation.Resource;
import java.util.List;


@Repository
public class OpenApiApprovalDao {

    @Resource
    private JPAQueryFactory jpaQueryFactory;

    private QOpenApiApproval qOpenApiApproval = QOpenApiApproval.openApiApproval;

    public List<OpenApiApproval> find(String appId) {

        JPAQuery<OpenApiApproval> query = jpaQueryFactory.select(qOpenApiApproval).from(qOpenApiApproval);

        if (StringUtils.isNotEmpty(appId)) {
            query.where(qOpenApiApproval.id.appId.eq(appId));
        }

        return query.fetch();
    }
}
